﻿package mvc_model
{
	import flash.events.Event;
	
	// Model class used to hold project data
	public class ProjectsPageModel extends Model
	{
		private var _projectList:XMLList;
		
		private var _currentProject:XML;
		private var _numProjects:int;
		
		public function ProjectsPageModel()
		{
			_numProjects = 0;
		}
		
		public function get numProjects():int
		{
			return _numProjects;
		}
		
		public function get title():String
		{
			//trace("Current index: " + currentIndex); 
			return _currentProject.title;
		}
		
		public function get url():String
		{
			return _currentProject.url;
		}
		
		public function get description():String
		{
			return _currentProject.description;
		}
		
		public function get startDate():String
		{
			return _currentProject.start_time;
		}
		
		public function get endDate():String
		{
			return _currentProject.end_time;
		}
		
		public function get creationDate():String
		{
			return _currentProject.date_of_creation;
		}
		
		public function get firstName():String
		{
			return _currentProject.first_name;
		}
		
		public function get lastName():String
		{
			return _currentProject.last_name;
		}
		
		public function myToString():String
		{
			var string:String = "Project title: " + title + "\n\n" + "Description: " + description + "\n\n"
			+ "Project created: " + creationDate;
			return string;
		}

		// protected method may not be needed
		override protected function updateData():void
		{
			// set the current user to be the user at index 'currentIndex'
			_currentProject = _projectList[currentIndex];
			
			// set the total number of users in the list
			totalItems = _projectList.length();
		}
		
		// set the projectList to be used by the view
		override protected function dataLoaded(event:Event):void
		{
			//trace(loader.data);
			data = new XML(loader.data);
			_projectList = data.project;
			_numProjects = _projectList.length();
			//trace("Num Projects:" + _numProjects);
			setCurrentIndex(0);
			
			//trace("loaded");
			if (_projectList == null) trace("project list null");
			//trace("Title:" + _projectList[1].title.toString());
			//trace(_projectList[0]);
		}
	}
}